package com.niuke;

/**
 * @ClassName : NC100
 * @Author : kele
 * @Date: 2023/4/2 17:13
 * @Description :
 */
public class NC100 {

    public static int solution(String s) {

        String str = s.trim();
        int num = 0;
        if (str.matches("^(\\d|(\\+(\\d)|-(\\d))).*")) {
            int flag = 1;
            if (str.startsWith("-")) {
                flag = -1;
            }

            if (str.startsWith("+") || str.startsWith("-")) {
                str = str.replace("+", "").replace("-", "").trim();
            }

            String str_num = str.split("\\D")[0];


            for (int i = 0; i < str_num.length(); ++i) {
                int ad = str_num.charAt(i) - '0';
                if (num > (num * 10 + ad)) {
                    if (flag == 1) {
                        return Integer.MAX_VALUE;
                    } else {
                        return Integer.MIN_VALUE;
                    }
                }
                num = (num * 10 + ad);
            }
            return flag * num;
        }

        return 0;

    }

    public static void main(String[] args) {

        System.out.println(solution("5+-5"));

//        String str = "+82";
//        System.out.println(str.matches("^(\\d|(\\+(\\d)|-(\\d))).*"));

    }
}
